package ui;

import tool.DrawLinesAndPointsWithAnnotations;
import ull.RoadLogic;

import javax.swing.*;

import static ui.View1.attractionLogic;

public class View extends JFrame {
    AttractionView view = new AttractionView();
    public View() {
        setTitle("西安邮电大学导航,欢迎您");
        JMenuBar menu = new JMenuBar();
        JMenu jMenu1 = new JMenu("查询");
        JMenu jMenu2= new JMenu("添加");
        JMenu jMenu3 = new JMenu("删除");
        JMenu jMenu4 = new JMenu("修改");
        JMenu jMenu6=new JMenu("刷新");
        JMenu jMenu5 = new JMenu("退出");
        JMenuItem jMenuItem1=new JMenuItem("查询路线");
        JMenuItem jMenuItem2=new JMenuItem("添加景点");
        JMenuItem jMenuItem3=new JMenuItem("删除景点");
        JMenuItem jMenuItem4=new JMenuItem("修改路线");
        JMenuItem jMenuItem10=new JMenuItem("修改景点");
        JMenuItem jMenuItem5=new JMenuItem("退出");
        JMenuItem jMenuItem6=new JMenuItem("添加线路");
        JMenuItem jMenuItem7=new JMenuItem("查看所有景点");
        JMenuItem jMenuItem8=new JMenuItem("删除路线");
        JMenuItem jMenuItem9=new JMenuItem("刷新");
        jMenu6.add(jMenuItem9);
        jMenu1.add(jMenuItem1);
        jMenu1.add(jMenuItem7);
        jMenu2.add(jMenuItem2);
        jMenu3.add(jMenuItem3);
        jMenu3.add(jMenuItem8);
        jMenu4.add(jMenuItem10);
        jMenu4.add(jMenuItem4);
        jMenu5.add(jMenuItem5);
        jMenu2.add(jMenuItem6);
        setJMenuBar(menu);
        menu.add(jMenu1);
        menu.add(jMenu2);
        menu.add(jMenu3);
        menu.add(jMenu4);
        menu.add(jMenu6);
        menu.add(jMenu5);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(800, 800);
        DrawLinesAndPointsWithAnnotations panel;
        panel = getDrawLinesAndPointsWithAnnotations();
        add(panel);
        setVisible(true);
        //查询路线
        jMenuItem1.addActionListener(e -> view.select());
        //添加景点
        jMenuItem2.addActionListener(e -> {
            dispose();
            view.add(new View());
        });
        //删除景点
        jMenuItem3.addActionListener(e -> {
            dispose();
            view.del(new View());
        });
        //修改路线
        jMenuItem4.addActionListener(e -> {
            dispose();
            view.modify(new View());
        });
        //退出系统
        jMenuItem5.addActionListener(e -> System.exit(0));
        //添加线路
        jMenuItem6.addActionListener(e -> {
            dispose();
            view.addRoad(new View());
        });
        //查看所有景点
        jMenuItem7.addActionListener(e -> view.selectAttractions());
        //删除路线
        jMenuItem8.addActionListener(e -> {
            dispose();
            view.deleteRoad(new View());
        });
        //刷新
        jMenuItem9.addActionListener(e -> {
            dispose();
            new View();
        });
        //修改景点
        jMenuItem10.addActionListener(e -> {
            dispose();
            view.modifyAttraction(new View());
        });
    }
    private static DrawLinesAndPointsWithAnnotations getDrawLinesAndPointsWithAnnotations() {
        int[][] lineCoordinates;
        RoadLogic roadLogic = new RoadLogic();
        lineCoordinates=attractionLogic.getLineCoordinates();
        int[][] pointCoordinates;
        pointCoordinates= attractionLogic.getPointCoordinates();
        String[] lineAnnotations;
        lineAnnotations=attractionLogic.getLineAnnotations();
        String[] pointAnnotations;
        pointAnnotations= attractionLogic.getPointAnnotations();
        return new DrawLinesAndPointsWithAnnotations(lineCoordinates,lineAnnotations,pointCoordinates,pointAnnotations);
    }
}